package org.dromara.crawler.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.crawler.domain.TemplateManager;
import org.dromara.crawler.domain.bo.ElementEventBo;
import org.dromara.crawler.domain.vo.ElementEventVo;
import org.dromara.crawler.mongo.mongodomain.Demo;
import org.dromara.crawler.mongo.mongodomain.ElementEvent;
import org.dromara.crawler.mongo.mongoservice.ElementEventService;
import org.dromara.crawler.service.TemplateManagerService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模版管理模块接口
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/templateManager")
public class TemplateManagerController {

    private final TemplateManagerService templateManagerService;

    /**
     * 模版信息查询
     */
    @GetMapping("/queryById/{templateId}")
    public R<TemplateManager> queryById(@PathVariable Long templateId) {
        return R.ok(templateManagerService.findById(templateId));
    }

    /**
     * 模版分页查询
     */
    @GetMapping("/queryByPage")
    public R<IPage<TemplateManager>> queryByPage(TemplateManager templateManager, PageQuery pageQuery) {
        return R.ok(templateManagerService.queryByPage(templateManager, pageQuery));
    }

    /**
     * 模版新增
     */
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody TemplateManager templateManager) {
        return R.ok(templateManagerService.addEntity(templateManager));
    }

    /**
     * 模版编辑
     */
    @PutMapping("/edit")
    public R<Boolean> edit(@RequestBody TemplateManager templateManager) {
        return R.ok(templateManagerService.updateById(templateManager));
    }

    /**
     * 模版删除
     */
    @DeleteMapping("/delete/{templateId}")
    public R<Boolean> delete(@PathVariable Long templateId) {
        return R.ok(templateManagerService.removeById(templateId));
    }


}
